package com.baseframe.auth.config;

import com.baseframe.auth.support.BaseArgon2PasswordEncoder;
import com.baseframe.auth.support.BaseNoPasswordEncode;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) //配置基于方法
public class BaseWebSecurityConfigurer extends WebSecurityConfigurerAdapter {


    /**
     * 配置认证管理器
     * @return 认证管理器 authenticationManagerBean
     */
    @Bean
    @Override
    @SneakyThrows
    public AuthenticationManager authenticationManagerBean() {
        return super.authenticationManagerBean();
    }


    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BaseArgon2PasswordEncoder();
    }



    @Override
    @SneakyThrows
    protected void configure(HttpSecurity http) {
        http.httpBasic().and().csrf().disable().authorizeRequests().anyRequest().fullyAuthenticated();
    }

}
